package com.furongji.common.result;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Result<T> {

    private Boolean success;

    private Integer code;

    private String message;

    private T data;

    private Result() {
    }

    public static <T> Result<T> build(T data) {
        Result<T> result = new Result<>();
        if (data != null)
            result.setData(data);
        return result;
    }

    public static <T> Result<T> success() {
        Result<T> result = build(null);
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = build(null);
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage("失败");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = build(data);
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> error(Integer code, String message) {
        Result<T> result = build(null);
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
